package compare;

import java.util.Comparator;
import java.util.Arrays;

class Student{
    public String name;
    public int age;
    public int score;
    public Student(String name,int age, int score){
        this.name = name;
        this.age = age;
        this.score = score;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", score=" + score +
                '}';
    }
}
//比较器
class AgeCompare implements Comparator<Student> {

    public int compare(Student o1,Student o2) {
        return o1.age - o2.age;
    }
}
class ScoreCompare implements Comparator<Student>{
    @Override
    public int compare(Student o1, Student o2){
        return o1.score - o2.score;
    }
}

public class Test {

    public static void main(String[] args){
        Student[] student =  new Student[3];
        student[0] = new Student("张三", 18,90);
        student[1] = new Student("李四",19,85);
        student[2] = new Student("小明",17,94);
        System.out.println("排序前:" + Arrays.toString(student));
        ScoreCompare scoreCompare = new ScoreCompare();
        Arrays.sort(student,scoreCompare);
        System.out.println("排序后:" + Arrays.toString(student));
    }
    public static void main1(String[] args){
        Student student1 = new Student("张三", 18,90);
        Student student2 = new Student("李四",19,85);
        Student student3 = new Student("小明",17,94);
        AgeCompare ageCompare = new AgeCompare();
        int ret = ageCompare.compare(student1, student2);
        System.out.println(ret);
    }
}
